package posts

import (
	"center-data-platform/app/content/api/internal/svc"
	"center-data-platform/app/content/api/internal/types"
	"center-data-platform/app/content/rpc/content"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type PostDetailLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPostDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PostDetailLogic {
	return &PostDetailLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PostDetailLogic) PostDetail(req *types.PostDetailReq) (resp *types.PostDetailResp, err error) {
	res, err := l.svcCtx.ContentRpc.Detail(l.ctx, &content.PostDetailReq{Id: req.Id})
	if err != nil {
		return nil, err
	}

	return &types.PostDetailResp{
		Id:          res.Data.Id,
		Title:       res.Data.Title,
		Description: res.Data.Description,
		Content:     res.Data.Content,
		Cover:       res.Data.Cover,
		Tags:        res.Data.Tags,
		Status:      int8(res.Data.Status),
		Type:        int8(res.Data.Type),
		CreatedAt:   res.Data.CreatedAt,
	}, nil
}
